package ModelLayer;

import java.util.ArrayList;

/**
 * @author (Gruppe C) 
 * @version (2012.11.09)
 */
public class Dvd
{
    // Fields
    private int id;
    private String title;
    private String artist;
    private String releaseDate;
    
    private static int nextId;
    
    // Psysical dvds.
    private ArrayList<Specimen> specimens;
    
    // Ctor
    public Dvd()
    {
        specimens = new ArrayList<Specimen>();
    }
    /*
     * DVD ctor
     * 
     * @param   id          DVD id.
     * @param   title       DVD title.
     * @param   artist      DVD artist.
     * @param   releaseDate DVD release date.
     */
    public Dvd(String title, String artist, String releaseDate)
    {
        this(); // Call ctor without parameters.
        nextId++; // Advance id.
        this.id = nextId;
        this.title = title;
        this.artist = artist;
        this.releaseDate = releaseDate;
    }
    
    public long getId()
    {
        return id;
    }
    
    public String getTitle()
    {
        return title;
    }
    
    public void print()
    {
        System.out.println(" DVD:");
        System.out.println(" Id: " + id);
        System.out.println(" Title: " + title);
        System.out.println(" Artist: " + artist);
        System.out.println(" Release Date: " + releaseDate);
    }
    
    /*
     * Adds a copy of the current dvd.
     * 
     * @param   specimen    Specimen of dvd (copy).
     */
    public void createCopy(Specimen specimen)
    {
        specimens.add(specimen);
    }
    
    public ArrayList<Specimen> getAllSpecimens()
    {
        return specimens;
    }
    
    public Specimen findAvailableSpecimen()
    {
        for (Specimen specimen : specimens)
        {
            if (!specimen.getIsLoaned())
            {
                specimen.setIsLoaned(true);
                return specimen;
            }
        }
        
        return null;
    }
}
